<?php

namespace Home\Controller;
/**
 * 商品分类
 * User: linkwhy
 * Date: 2015/10/26
 * Time: 10:23
 */
class GoodsClassController extends HomeController{

    private $mode = '';

    public function _initialize(){
        $this->mode = M('goods_class');
    }

    public function index(){
        $data['uid'] = $_SESSION['userid'];
        $data['shopid'] = $_SESSION['shopid'];
        $this->assign('data', $data);
        $this->assign('list', $this->getAllgoods());
        $this->display();
    }

    /**
     * 获取菜品分类所有分类信息
     * @return mixed
     */
    public function getAllgoods(){
        $dclass = M('goods_class');
        $where['pid'] = 0;
        $list = $dclass->field('id,pid,name')->where($where)->select();
        foreach($list as $key => $v){
            $temp_list = $dclass->field('id,pid,name')->where(array('pid' => $v['id']))->select();
            foreach($temp_list as $k2 => $v2){
                $list[$key]['_child'][$k2]['id'] = $v2['id'];
                $list[$key]['_child'][$k2]['name'] = $v2['name'];
            }
            unset($temp_list);
        }
        return $list;
    }

}
